package com.fanben100.biz;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Properties;

import com.fanben100.constant.SystemConstant;
import com.fanben100.domain.SysConfig;
import com.fanben100.exception.LoadConfigException;

/**
 * 内部Properties文件读取配置
 * 
 * @author Administrator
 * 
 */
public class InnerPropertyStrategy extends PropertyStrategy {

	@Override
	public void algorithmInterface(String... fileName)
			throws LoadConfigException {
		URL resourcePath = this.getClass().getResource(
				"/config/" + SystemConstant.UI_CONFIG_PATH);
		InputStream in = null;
		if (resourcePath == null) {
			throw new LoadConfigException("无法找到系统配置资源", null);
		}
		try {
			in = resourcePath.openStream();
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		// InputStream in = this.getClass().getClassLoader()
		// .getResourceAsStream(resourcePath);
		Properties p = new Properties();
		if (in != null) {
			try {
				p.load(in);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (p != null) {
				try {
					SysConfig.sellerId = Integer.valueOf(p
							.getProperty(SystemConstant.SELLER_ID_KEY));
					SysConfig.sellerName = p
							.getProperty(SystemConstant.SELLER_NAME_KEY);
					SysConfig.loaded = true;
				} catch (NumberFormatException nfe) {
				}
			}
		}
	}
}
